# coding=utf-8
from appium.webdriver.common.mobileby import MobileBy
from Base.basepage import BasePage
from common.LoggerUtil import LogUtils


class Es_Clock_Page(BasePage):

    loc_image_mine = (MobileBy.ID, "com.youth.startup:id/image_mine") # 点击底部我的按钮
    loc_line_bedearly = (MobileBy.ID, "com.youth.startup:id/line_bedearly") # 点击早睡
    loc_widgetToast = (MobileBy.XPATH, "/hierarchy/android.widget.Toast")  # 获取早睡打卡信息
    loc_line3 = (MobileBy.ID, "com.youth.startup:id/text_line3")  # 取消分享
    loc_number = (MobileBy.ID, "com.youth.startup:id/text_head_number")  # 打卡天数
    loc_back = (MobileBy.ID, "com.youth.startup:id/image_back")  # 返回
    loc_line_index = (MobileBy.ID, "com.youth.startup:id/line_index")  # 点击底部首页按钮



    def es_clock_page(self):
        try:
            self.locator(self.loc_image_mine).click()
            self.locator(self.loc_line_bedearly).click()
            res = self.get_toast(self.loc_widgetToast).text
            self.take_screenshot("【早睡打卡】截图_")
            if res == '打卡成功，奖励+5积分':
                LogUtils.info('----早睡打卡：%s----', res)
                self.locator(self.loc_line3).click()
            elif res == '今日已签到':
                LogUtils.info('----早睡打卡：%s----', res)
            elif res == '请在每日 18:00~02:00 期间打卡':
                LogUtils.info('----早睡打卡：%s----', res)
            else:
                return "早睡打卡异常！"
            text_number = self.locator(self.loc_number).text
            LogUtils.info('----早睡打卡天数：%s----', text_number)
            self.locator(self.loc_back).click()
            self.locator(self.loc_line_index).click()
        except Exception as e:
            LogUtils.error(f'早睡打卡异常{e}-----')
            self.take_screenshot("【早睡打卡异常】截图_")

